package generic1;

import java.util.Comparator;
import java.util.HashSet;
import java.util.TreeSet;

/**
 * @Auther: 杨通通
 * @Date: 2024/10/23 23:27
 * @Description:
 */
public class Test08 {

    public static void main(String[] args) {
        TreeSet<Cat> treeSet = new TreeSet<>(new Comparator1());
//        TreeSet<Cat> treeSet = new TreeSet<>(new Comparator2());
        treeSet.add(new Cat("jimi",13));
        treeSet.add(new Cat("ali",18));
        treeSet.add(new Cat("ber",26));

        for (Cat c :
                treeSet) {
            System.out.println(c);
        }
    }
}
class Comparator1 implements Comparator<Animal> {


    @Override
    public int compare(Animal o1, Animal o2) {
        return o1.name.compareTo(o2.name);
    }
}

class Comparator2 implements Comparator<Cat>{

    @Override
    public int compare(Cat o1, Cat o2) {
        return o1.age - o2.age;
    }
}
class Comparator3 implements Comparator<MiniCat>{

    @Override
    public int compare(MiniCat o1, MiniCat o2) {
        return o1.level - o2.level;
    }
}